package com.education.business.service.education;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.education.business.mapper.education.TestPaperInfoStudentMapper;
import com.education.business.mapper.system.ExamRoomStudentMapper;
import com.education.business.service.BaseService;
import com.education.common.model.PageInfo;
import com.education.common.utils.FileUtil;
import com.education.model.dto.ExamRoomStudentDto;
import com.education.model.dto.TestPaperInfoDto;
import com.education.model.dto.TestPaperInfoStudentDto;
import com.education.model.entity.ExamRoomStudent;
import com.education.model.entity.TestPaperInfoStudent;
import com.education.model.request.PageParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TestPaperInfoStudentService extends BaseService<TestPaperInfoStudentMapper, TestPaperInfoStudent> {
    @Autowired
    private TestPaperInfoStudentMapper testPaperInfoStudentMapper;
    private ExamRoomStudentMapper examRoomStudentMapper;
    /**
     * 监考端-考生列表
     * @param pageParam
     * @param testPaperInfoStudent
     * @return
     */
    public PageInfo<TestPaperInfoStudentDto> invStudentList(PageParam pageParam, TestPaperInfoStudent testPaperInfoStudent) {
        Page<TestPaperInfoStudentDto> page = new Page(pageParam.getPageNumber(), pageParam.getPageSize());
        return selectPage(baseMapper.invStudentList(page, testPaperInfoStudent));
    }
    /**
     * 按考场统计学生人数
     * @param
     * @return
     */

    public PageInfo<TestPaperInfoStudentDto> selectPageList(PageParam pageParam, TestPaperInfoStudent testPaperInfoStudent) {
        Page<TestPaperInfoStudentDto> page = new Page(pageParam.getPageNumber(), pageParam.getPageSize());
        return selectPage(baseMapper.selectPageList(page, testPaperInfoStudent));
    }
    /**
     * 根据id实现批量删除
     *
     * @param
     * @param maps
     * @return
     */
    public int deleteStudentAllById(List maps) {
        return testPaperInfoStudentMapper.deleteBatchIds(maps);
    }

    /**
     * 批量添加-考生列表
     */
    public PageInfo<TestPaperInfoStudentDto> paperStudentList(PageParam pageParam, TestPaperInfoStudentDto testPaperInfoStudent) {
        Page<TestPaperInfoStudentDto> page = new Page(pageParam.getPageNumber(), pageParam.getPageSize());
        return selectPage(baseMapper.paperStudentList(page, testPaperInfoStudent));
    }

    /**
     * 根据考试任务查询
     * 读取并写入json文件
     * @param taskid
     * @return
     */
    public List<TestPaperInfoStudent> TestPaperInfoStudentByTaskId(int taskid){
        List<TestPaperInfoStudent> studentList = baseMapper.TestPaperInfoStudentByTaskId(taskid);
        FileUtil.WriteFile("testPaperInfoStudent"+".json",FileUtil.tojson(studentList));
        return baseMapper.TestPaperInfoStudentByTaskId(taskid);
    }
    public int saveAll(TestPaperInfoStudent testPaperInfoStudent){
        return baseMapper.saveAll(testPaperInfoStudent);
    }

}
